package com.day20.ex11;

public class Box {
    private int milk;
    private  boolean state=false;
    public synchronized void put(int milk){
        if (state){
            try {
                wait();
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        }
        this.milk=milk;
        System.out.println(this.milk);
        state=true;
        notifyAll();
    }
    public synchronized void get(){
        if (!state){
            try {
                wait();
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        }
        System.out.println("取走"+this.milk);
        state=false;
        notifyAll();
    }
}
